/**
 * @author phi
 */

var $id = function(id)
{
    return document.getElementById(id);
};
var $class = function(c, i)
{
    i = i || 0;
    return document.getElementsByClassName(c)[i];
};

(function(){
    
    var title   = "untitled";
    var number  = 1;
    
    window.onload = function()
    {
        $id("change").addEventListener("click", changeTitle, false);
        for (var i=0; i<4; ++i) {
            $class("num-button", i).addEventListener("click", changeNumber, false);
        }
        setHistory();
        
        if (location.hash) {
            var str = location.hash.substr(1);
            number = str[0];
            title = str.substr(2);
            
            refreshTitle();
            
            changeIcon();
        }
    };
    
    var changeTitle = function()
    {
        title = prompt("Title : ", "untitled");
        refreshTitle();
    };
    
    var changeNumber = function(e)
    {
        number = e.target.innerHTML;
        refreshTitle();
    }
    
    var refreshTitle = function()
    {
        var str = number + ":" + title;
        
        location.hash           = str;
        document.title          = str;
        $id("title").innerHTML  = str;
        
        // alert($id("shortcut-icon").href);
        // $id("shortcut-icon").href = number + "celtic.ico";
        // 
        // sessionStorage.setItem()
    };
    
    var changeIcon = function()
    {
        var link = document.createElement("link");
        link.type = "image/x-icon";
        link.rel = "shortcut icon";
        link.href = number + "celtic.ico";
        
        document.getElementsByTagName("head")[0].appendChild(link);
    }
    
    var setHistory = function()
    {
        if (sessionStorage.length <= 0) return ;
        
        for (var i=0; i<sessionStorage.length; ++i) {
            
        }

    };

    
})();







